package common;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class DocumentMaskNumber extends PlainDocument{
	private int maxDigits = 8;
	
	public DocumentMaskNumber(int maxDigits) {
		this.maxDigits = maxDigits;
	}
	
	public int getMaxDigits() {
		return maxDigits;
	}
	public void setMaxDigits(int maxDigits){
		this.maxDigits = maxDigits;
	}
	
	public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {		
		if(getLength() < maxDigits){
			char c = str.charAt(0);			
			
			if(Character.isDigit(c)){
				super.insertString(offs, str, a);
			}
		}		
	}
}
